var app = getApp()
Page({
    data: {
      istokenPop: false, //判断是否等了
      tabBarHeight: 0,
      list: [],
      wasActivities: ''
    },

    //扫码
    saoma () {
      wx.navigateTo({
        url: '/package/juanshu/pages/saoma/saoma',
      })
    },

    // onShow () {
    //   console.log(this.getTabbar())
    // },

    // 买书
    buyBook () {
      if (wx.getStorageSync('token') == '') {
        this.setData({
          istokenPop: true
        })
        return
      }
      if (this.wasActivities!='') {
        wx.navigateTo({
          url: '/package/juanshu/pages/buyBook/buyBook?wasActivities=' + this.data.wasActivities,
        })
      }
    },


    //获取底部tabbar的高度

    getTabbar () {
    let systemInfo = wx.getSystemInfoSync()
      // px转换到rpx的比例
        let pxToRpxScale = 750 / systemInfo.windowWidth;
    // 状态栏的高度
    let ktxStatusHeight = systemInfo.statusBarHeight * pxToRpxScale
        // 导航栏的高度
        let navigationHeight = 44 * pxToRpxScale
        // window的宽度
        let ktxWindowWidth = systemInfo.windowWidth * pxToRpxScale
        // window的高度
        let ktxWindowHeight = systemInfo.windowHeight * pxToRpxScale
        // 屏幕的高度
        let ktxScreentHeight = systemInfo.screenHeight * pxToRpxScale
        // 底部tabBar的高度
        let tabBarHeight = ktxScreentHeight - ktxStatusHeight - navigationHeight - ktxWindowHeight

         this.setData ({
           tabBarHeight: tabBarHeight
         })
  },



  // 接口部分

  getGotolist() {
    // console
    app.request('sdx/order/donate/donate/goto/list',{},'POST').then(res => {
      console.log(res)
    })
  },


  // onShow () {
  //   this.getGotolist()
  //   wx.pageScrollTo({
  //     scrollTop: 0
  //   })
  // },

  //获取卖款播报
  getList () {


    var params = {
      page: 1,
      size: 5
    }

    var _this = this
    var url = wx.getStorageSync('token') != '' ? 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/user/global/donate/auth' :'https://devapi.xiaoshitimebank.com/user/sdx/sdx/user/global/donate'
    wx.request({
      url: url,
      data: params,
      method: 'POST',
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
      "token" : wx.getStorageSync('token'),
        "uid" : wx.getStorageSync('uuid')
      },
      success: (res)=>{
        if (res.data.code == 200) {
          var arr = res.data.data
          _this.setData({
            list: arr
          })
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      }
    })
  },


  // 买书规则
  buyBookRoule () {
    wx.navigateTo({
      url: '/package/juanshu/pages/buyRoule/buyRoule',
    })
  },


  onShow () {


    console.log(app.globalData.wasActivities)
    this.getGotolist()
    wx.pageScrollTo({
      scrollTop: 0
    })
    this.getList()
  },


  onLoad (options) {
    // console.log(app.globalData.wasActivities)
    // if (options.wasActivities!=0) {
    //   this.setData({
    //     wasActivities: 1
    //   })
    // }
  },


  //取消弹框
  touchMove() {
    this.setData({
      istokenPop: true
    })
  },


  loginCode() {
    this.setData({
      istokenPop: false
    })

    // this.onLoad()
    this.onShow()
  }
})
